<?php

/***

LZRoster: A roster for World of Warcraft.
Copyright (C) 2007  Emmanuel Cron

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.

***/

require_once "class/Load.class.php";
require_once "class/Config.class.php";
require_once "class/File.class.php";
require_once "class/FileParser.class.php";
require_once "class/FileImporter.class.php";
require_once "class/Inputs.class.php";
require_once "class/StatusRoster.class.php";
require_once "class/SessionRoster.class.php";
require_once "class/Localization.class.php";

$load = Load::GetInstance();
$inputs = Inputs::GetInstance();
$config = Config::GetInstance();
$localization = Localization::GetInstance();
$status_roster = StatusRoster::GetInstance();
$session_roster = SessionRoster::GetInstance();

if ($session_roster->IsConnected() == false)
{
	$session_roster->Redirect("connection.php");
}

if ($inputs->HasPostData('has_send_file'))
{
	$file = File::GetInstance();
	
	if ( $file->HasFile('LZProfiler') == false )
	{
		$status_roster->AddError( $localization->Get('file not found') );
	}
	else
	{
		$file->CheckFileStatus('LZProfiler');
	}
	
	if ($status_roster->HasError() == false)
	{
		if ($file->GetFileName('LZProfiler') != "LZProfiler.lua")
		{
			$status_roster->AddError( $localization->Get('the uploaded file was not the correct one') );
		}
		else
		{
			$file_parser = new FileParser( $file->GetFileContents('LZProfiler') );
			
			if ( $file_parser->IsSuccessful() == false )
			{
				$status_roster->AddError( $localization->Get('the file does not seem to be a valid Lua file') );
			}
			else
			{
				$file_importer = new FileImporter($file_parser->GetParsedData());
				
				$file_importer->Import();
			}
		}
	}
	
	$session_roster->SaveStatus($status_roster);
	$session_roster->Redirect("send.php");
}

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="fr">
	<head>
		<title>LZRoster<?php echo $config->HasRosterTitle() ?  " - ".$config->GetRosterTitle() : null; ?></title>
		<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
		<link rel="stylesheet" media="screen" type="text/css" href="styles/_.css" />
		<link rel="stylesheet" media="screen" type="text/css" href="styles/send.css" />
	</head>
	<body>
		
		<?php require_once "inc/head.php"; ?>
		<?php require_once "inc/hmenu.php"; ?>
		
		<h2><?php echo $localization->Get('send'); ?></h2>
		
		<?php
		if ($status_roster->HasMessage() or $session_roster->HasStatus())
		{
		?>
			
			<p>
				<?php echo $localization->Get('this page produced some messages. please refer to the following lines'); ?>
			</p>
			
			<?php echo $session_roster->HasStatus() ? $session_roster->GetStatus()->GetStack_InList() : $status_roster->GetStack_InList(); ?>
			
			<p>
				<?php echo $localization->Get('you can refresh the page %s and try again', "send.php"); ?>
			</p>
			
		<?php
		}
		else
		{
		?>
		
		<form action="send.php" enctype="multipart/form-data" method="post" onsubmit="send.disabled='disabled'; send.value='<?php echo $localization->Get('please wait'); ?>';" class="send">
		<p>
			<span style="font-size: 12pt; font-weight: bold;"><?php echo $localization->Get('how to proceed'); ?></span><br />
			<?php echo $localization->Get('in order for your crafts to be saved, you need (...) %s LZProfiler (...)', "addon.php"); ?>
		</p>
		<p>
			<span style="font-size: 12pt; font-weight: bold;"><?php echo $localization->Get('known bugs'); ?></span><br />
		</p>
		<p>
			<?php echo $localization->Get('the upload of the file can fail on some computers (...)'); ?>
		</p>
		<p>
			<span style="font-size: 12pt; font-weight: bold;"><?php echo $localization->Get('finding the file'); ?></span><br />
			<?php echo $localization->Get('you can easily send your data from this page'); ?><br />
			<?php echo $localization->Get('select the file to send and click on send'); ?>
		</p>
		<p style="text-align: center;">
			<input type="file" name="LZProfiler" /><br />
			<em><?php echo $localization->Get('the file can be found here'); ?><br />
			\World of Warcraft\WTF\Account\&lt;Login&gt;\SavedVariables\LZProfiler.lua</em>
		</p>
		<p style="text-align: center;">
			<input type="submit" value="<?php echo $localization->Get('send'); ?>" id="send" />
			<input type="hidden" name="has_send_file" />
		</p>
		</form>
		
		<?php
		}
		?>
		
		<?php require_once "inc/foot.php"; ?>
		
	</body>
</html>